package com.pandora.credit.mongo.dao.impl;

import com.pandora.credit.mongo.dao.MongoPandoraCreditDao;
import com.pandora.credit.mongo.entity.MongoPandoraCredit;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author developer
 */
@Repository("mongoPandoraCreditDaoImpl")
public class MongoPandoraCreditDaoImpl implements MongoPandoraCreditDao {
    @Resource
    private MongoTemplate mongoTemplatePc;

    @Override
    public List<MongoPandoraCredit> selectByIds(List<Long> ids){
        Query query = new Query();
        Criteria criteria = Criteria.where("_id").in(ids);
        query.addCriteria(criteria);
        List<MongoPandoraCredit> li = mongoTemplatePc.find(query, MongoPandoraCredit.class);
        return li;
    }

    @Override
    public MongoPandoraCredit selectByType(int type) {
        Query query = new Query();
        Criteria criteria = Criteria.where("_id").is(type);
        query.addCriteria(criteria);
        MongoPandoraCredit mongoPandoraCredit = mongoTemplatePc.findOne(query, MongoPandoraCredit.class);
        return mongoPandoraCredit;
    }

    @Override
    public List<MongoPandoraCredit> selectByTypeIds(int type, List<Long> ids) {
        Query query = new Query();
        Criteria criteria = Criteria.where("type").is(type).and("_id").in(ids);
        query.addCriteria(criteria);
        List<MongoPandoraCredit> li = mongoTemplatePc.find(query, MongoPandoraCredit.class);
        return li;
    }

    @Override
    public MongoPandoraCredit selectById(long id) {
        Query query = new Query();
        Criteria criteria = Criteria.where("_id").is(id);
        query.addCriteria(criteria);
        MongoPandoraCredit mongoPandoraCredit = mongoTemplatePc.findOne(query, MongoPandoraCredit.class);
        return mongoPandoraCredit;
    }
}
